﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CodeStudy.EF;
using System.Configuration;
using System.Data.Linq;

namespace CodeStudy.Test
{
    /// <summary>
    /// Summary description for EntityFrameworkTest
    /// </summary>
    [TestClass]
    public class EntityFrameworkTest
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityFrameworkTest"/> class.
        /// </summary>
        public EntityFrameworkTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        protected string ConnectionString { get { return ConfigurationManager.ConnectionStrings["NorthWindEntities"].ToString(); } }

        [TestMethod]
        public void CustomerTest()
        {
            CodeStudy.EF.NorthWindEntities entities = new NorthWindEntities(this.ConnectionString);

            var customerList1 = from customer in entities.Customers
                               where customer.CompanyName != string.Empty
                               select customer;
            var customerList2 = entities.Customers.Where((customer) => customer.CompanyName != string.Empty);

            Assert.AreEqual(customerList1.Count<Customers>(), customerList2.Count<Customers>());
        }


    }
}
